/****************************************************************************************** 
 *	ActionScript JSFL API is under an MIT license.
 *
 *	Copyright (c) 2010 Digital Primates IT Consulting Group
 *
 *	Permission is hereby granted, free of charge, to any person obtaining a copy of this
 *	software and associated documentation files (the "Software"), to deal in the Software 
 *	without restriction, including without limitation the rights to use, copy, modify, 
 *	merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 
 *	permit persons to whom the Software is furnished to do so, subject to the following 
 *	conditions:
 *
 *	The above copyright notice and this permission notice shall be included in all copies
 *	or substantial portions of the Software.
 *
 *	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 *	INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
 *	PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
 *	HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 *	CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
 *	OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
 * 
 *******************************************************************************************/

package flash.extension.panel
{
	import adobe.utils.MMExecute;

	public class ActionsPanel
	{
		
		/**
		 * Returns the class of a specified variable. 
		 * 
		 */
		public static function getClassForObject( asVariableName:String ):String
		{
			return MMExecute("fl.actionsPanel.getClassForObject('"+ asVariableName +"')") as String;
		}
		
		/**
		 * Specifies whether Script Assist mode is enabled. Returns boolean indicating success.
		 * @return 
		 * 
		 */
		public static function getScriptAssistMode():Boolean
		{
			var assistMode:String = MMExecute("fl.actionsPanel.getScriptAssistMode()");
			return (assistMode == "true" ? true : false);
		}
		
		/**
		 * Returns the text that is currently selected in the Actions panel.
		 * @return 
		 * 
		 */
		public static function getSelectedText():String
		{
			return MMExecute("fl.actionsPanel.getSelectedText()") as String;			
		}
		
		/**
		 * Returns the text in the Actions panel.
		 * @return 
		 * 
		 */
		public static function getText():String
		{
			return MMExecute("fl.actionsPanel.getText()") as String;
		}		
		
		/**
		 * Specifies whether any text is currently selected in the Actions panel. 
		 * @return 
		 * 
		 */
		public static function get hasSelection():Boolean
		{			
			var hasSelection:String = MMExecute("fl.actionsPanel.hasSelection()");	
			return ((hasSelection == "true") ? true : false);
		}
	
		/**
		 * Replaces the currently selected text with specified text. Returns boolean indicating success.
		 * @param value
		 * @return 
		 * 
		 */
		public static function replaceSelectedText( value:String ):Boolean
		{
			var textReplaced:String = MMExecute("fl.actionsPanel.replaceSelectedText('" + value + "')");
			return (textReplaced == "true" ? true : false);					
		}
		
		/**
		 * Enables or disables Script Assist mode. Returns boolean indicating success.
		 * @param value
		 * @return 
		 * 
		 */
		public static function setScriptAssistMode( value:Boolean ):Boolean
		{
			var assistMode:String = MMExecute("fl.actionsPanel.setScriptAssistMode(" + value + ")");
			return (assistMode == "true" ? true : false);
		}
		
		/**
		 * Selects a specified set of characters in the Actions panel. Returns boolean indicating success.
		 * @param startIndex
		 * @param numberOfChars
		 * @return 
		 * 
		 */
		public static function setSelection( startIndex:int, numberOfChars:int ):Boolean
		{
			var selectionSet:String = MMExecute("fl.actionsPanel.setSelection(" + startIndex + ", " + numberOfChars + ")");
			return (selectionSet == "true" ? true : false);									
		}
		
		/**
		 * Clears any text in the Actions panel and then adds specified text. Returns boolean indicating success.
		 * @param value
		 * @return 
		 * 
		 */
		public static function setText( value:String ):Boolean
		{
			var newText:String = MMExecute("fl.actionsPanel.setText('"+ value +"')");
			return (newText == "true" ? true : false);	
		}
	}
}